package org.example.handler;

import org.example.config.MqttGateway;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.mqtt.support.MqttHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Service;

/**
 * MQTT消息发送者
 *
 * @author Brant
 * @since 2025-04-21
 */
@Service
public class MqttMessageSender {
    /**
     * MQTT消息网关
     */
    @Autowired
    private MqttGateway mqttGateway;

    /**
     * 发送MQTT消息
     *
     * @param topic   主题
     * @param payload 消息体
     */
    public void sendMsg(@Header(value = MqttHeaders.TOPIC) String topic, String payload) {
        mqttGateway.sendMsgToMqtt(topic, payload);
    }

    /**
     * 发送MQTT消息
     *
     * @param topic   主题
     * @param qos     QOS
     * @param payload 消息体
     */
    public void sendMsg(@Header(value = MqttHeaders.TOPIC) String topic, @Header(value = MqttHeaders.QOS) int qos, String payload) {
        mqttGateway.sendMsgToMqtt(topic, qos, payload);
    }
}